from fastapi import APIRouter, Depends

from app.core.responses import Response
from app.schemas.enum import CircleListType
from app.services.auth import get_current_user
from app.services.circle import CircleServices
from app.schemas.circle import CirclePostsSM, CircleLikesSM, CircleCommentsSM

router = APIRouter()


# @router.get('/circle_posts')
# def circle_list(page: int = 0, page_size: int = 10):
#     data = CircleServices.posts_list(page, page_size)
#     return Response.success(data)


@router.get('/circle_posts')
def circle_friends_list(list_type: CircleListType, page: int = 1, page_size: int = 10,
                        user: str = Depends(get_current_user)):
    print(list_type.value)
    if list_type.value == CircleListType.friends:
        data = CircleServices.circle_friends(user.id, page, page_size)
        return Response.success(data)
    else:
        data = CircleServices.circle_recommend(page, page_size)
        return Response.success(data)


@router.post('/circle_posts')
def circle_store(form: CirclePostsSM, user: str = Depends(get_current_user)):
    if CircleServices.posts_store(user.id, form):
        return Response.message('操作成功！')
    return Response.message('操作失败！')


@router.delete('/circle_posts')
def circle_destroy(posts_id):
    if CircleServices.posts_destroy(posts_id):
        return Response.message('操作成功！')
    return Response.message('操作失败！')


@router.post('/circle_likes')
def circle_store(form: CircleLikesSM, user: str = Depends(get_current_user)):
    if CircleServices.likes_store(user.id, form):
        return Response.message('操作成功！')
    return Response.message('操作失败！')


@router.delete('/circle_likes')
def circle_destroy(likes_id):
    if CircleServices.likes_destroy(likes_id):
        return Response.message('操作成功！')
    return Response.message('操作失败！')


@router.post('/circle_comments')
def circle_store(form: CircleCommentsSM, user: str = Depends(get_current_user)):
    if CircleServices.comments_store(user.id, form):
        return Response.message('操作成功！')
    return Response.message('操作失败！')


@router.delete('/circle_comments')
def circle_destroy(likes_id):
    if CircleServices.comments_destroy(likes_id):
        return Response.message('操作成功！')
    return Response.message('操作失败！')
